package com.gh.yygh.hosp.service.impl;

import com.alibaba.excel.util.StringUtils;
import com.cloopen.rest.sdk.BodyType;
import com.cloopen.rest.sdk.CCPRestSmsSDK;
import com.gh.yygh.hosp.service.MsmService;
import com.gh.yygh.hosp.utils.ConstantPropertiesUtils;
import com.gh.yygh.vo.msm.MsmVo;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class MsmServiceImpl implements MsmService {
    //发送验证码
    @Override
    public boolean send(String phone, String phoneCode) {
        System.out.println("Service Phone = " + phone);
        System.out.println("Service phoneCode = " + phoneCode);
        //判断手机号是否为空
        if(StringUtils.isEmpty(phone)) {
            return false;
        }
        //return true;
        System.out.println("ConstantPropertiesUtils.ACCOUNT_S_ID = " + ConstantPropertiesUtils.ACCOUNT_S_ID);
        System.out.println("ConstantPropertiesUtils.ACCOUNT_TOKEN = " + ConstantPropertiesUtils.ACCOUNT_TOKEN);
        System.out.println("ConstantPropertiesUtils.APP_ID = " + ConstantPropertiesUtils.APP_ID);
        System.out.println("ConstantPropertiesUtils.SERVER_IP = " + ConstantPropertiesUtils.SERVER_IP);
        System.out.println("ConstantPropertiesUtils.SERVER_PORT = " + ConstantPropertiesUtils.SERVER_PORT);
        //容联云发送短信
        CCPRestSmsSDK ccpRestSmsSDK = new CCPRestSmsSDK();
        ccpRestSmsSDK.setAccount(ConstantPropertiesUtils.ACCOUNT_S_ID,ConstantPropertiesUtils.ACCOUNT_TOKEN);
        ccpRestSmsSDK.setAppId(ConstantPropertiesUtils.APP_ID);
        ccpRestSmsSDK.setBodyType(BodyType.Type_JSON);
        ccpRestSmsSDK.init(ConstantPropertiesUtils.SERVER_IP,ConstantPropertiesUtils.SERVER_PORT);

        String[] datas = {phoneCode,"5"};
        HashMap<String,Object> result = ccpRestSmsSDK.sendTemplateSMS(phone,"1",datas);
        if("000000".equals(result.get("statusCode"))){
            return true;
        }else {
            return false;
        }
    }

    //mq发送短信
    @Override
    public boolean send(MsmVo msmVo) {
        System.out.println("MsmVo = " + msmVo);
        String phone = msmVo.getPhone();
        if(!StringUtils.isEmpty(msmVo.getPhone())) {
            //String code = (String)msmVo.getParam().get("code");
            String phoneCode = msmVo.getPhoneCode();
            return this.send(phone,phoneCode);
        }
        return false;

    }
}
